package com.dongdongshop.controller;

import com.dongdongshop.data.PageBean;
import com.dongdongshop.data.Result;
import com.dongdongshop.data.ResultEnum;
import com.dongdongshop.pojo.TbGoods;
import com.dongdongshop.service.GoodsService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("goods")
public class GoodsController {

    @DubboReference
    private GoodsService goodsService;

    @RequestMapping("getGoodsList")
    @ResponseBody
    public Result getGoodsList(@RequestParam(defaultValue = "1")Integer pageNumber,@RequestParam(defaultValue = "5")Integer pageSize,String goodsName){
        try{
            PageBean<TbGoods> goodsList = goodsService.getGoodsList(pageNumber,pageSize,goodsName);
            return Result.ok().setData(goodsList);
        }catch (Exception e){
            e.printStackTrace();
            return Result.respones(ResultEnum.ERROR);
        }
    }

    @RequestMapping("setStatu")
    @ResponseBody
    public Result setStatu(@RequestParam("id[]")Long[] id,String status){
        try{
            goodsService.setStatu(id,status);
            return Result.ok();
        }catch (Exception e){
            e.printStackTrace();
            return Result.respones(ResultEnum.ERROR);
        }
    }

}

